사이트 내 전체검색
PHP
[php] imagettftext 사용할때 문자열 정렬하기
로빈아빠
https://cmd.kr/php/769 URL이 복사되었습니다.

본문

SIMPLE OVERLOADED FUNCTION: Adds TTF Center and Right Alignment to co ordintate points. 
Correctly demonstrates the use of the bouning box TTF function and the array of coordinates that it returns. 

After obtaining values and adjusting based on a set of values [L, C, R], it uses simple math based of the length of the text to move it from the origin (x = 0 ) 

<?php 
function imagettftextalign($image$size$angle$x$y$color$font$text$alignment='L'


   
//check width of the text 
   
$bbox imagettfbbox ($size$angle$font$text); 
   
$textWidth $bbox[2] - $bbox[0]; 
   switch (
$alignment) { 
       case 
"R"
           
$x -= $textWidth
           break; 
       case 
"C"
           
$x -= $textWidth 2
           break; 
   } 

   
//write text 
   
imagettftext ($image$size$angle$x$y$color$font$text); 


?>

댓글목록

등록된 댓글이 없습니다.

PHP
871 (4/18P)

Search

Copyright © Cmd 명령어 18.118.16.229